﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Text;
using FrameWork;
using FrameWork.Components;
using FrameWork.web.Code;

namespace FrameWork.web.Module.ITMS.KnowledgeBase.KBQuery
{
    public partial class Default : System.Web.UI.Page
    {
        int KindID;
        protected void Page_Load(object sender, EventArgs e)
        {
            KindID = (int)Common.sink("KID", MethodType.Get, 255, 0, DataType.Int);
            HeadMenuWebControls1.ButtonList[0].ButtonUrl = string.Format("Manager.aspx?CMD=New&KID={0}", KindID);
            if (!Page.IsPostBack)
            {
                Session["its_KnowledgeBaseEntity"] = null;
                its_KnowledgeBaseEntity kb = new its_KnowledgeBaseEntity();
                kb.KID = KindID;
                txtKID.Text = KindID.ToString();
                Session["its_KnowledgeBaseEntity"] = kb;
                BindDataList();
            }
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        private void BindDataList()
        {
            its_KnowledgeBaseCs kbCs = new its_KnowledgeBaseCs();
            its_KnowledgeBaseEntity kb = Session["its_KnowledgeBaseEntity"] as its_KnowledgeBaseEntity;
            if (kb == null)
            {
                kb = new its_KnowledgeBaseEntity();
            }
            DataTable dt = kbCs.Knowledge_Select(kb, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize);
            int iCount = kbCs.Knowledge_Count(kb);
            this.GridView1.DataSource = dt;
            this.GridView1.DataBind();
            this.AspNetPager1.RecordCount = iCount;
        }

        /// <summary>
        /// 点击分页事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindDataList();
        }

        /// <summary>
        /// 查询条件
        /// </summary>
        private string SearchTerms
        {
            get
            {
                if (ViewState["SearchTerms"] == null)
                    ViewState["SearchTerms"] = " Where 1=1 ";
                return (string)ViewState["SearchTerms"];
            }
            set { ViewState["SearchTerms"] = value; }
        }

        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = 1;
            string KID_Value = (string)Common.sink(txtKID.UniqueID, MethodType.Post, 10, 0, DataType.Str);
        
            string Subject_Value = (string)Common.sink(txtSubject.UniqueID, MethodType.Post, 200, 0, DataType.Str);
            string Content_Value = (string)Common.sink(txtContent.UniqueID, MethodType.Post, 200, 0, DataType.Str);
            string KeyWord_Value = (string)Common.sink(txtKeyWord.UniqueID, MethodType.Post, 50, 0, DataType.Str);
            

            its_KnowledgeBaseEntity kb = new its_KnowledgeBaseEntity();
            KindID = (int)Common.sink("KID", MethodType.Get, 255, 0, DataType.Int);
            if (!CheckBox1.Checked)
            {
                kb.KID = KindID;
            }
            //Context_Value != string.Empty
            if (Subject_Value != string.Empty)
            {
                kb.Subject = Subject_Value.Trim();
            }
            if (Content_Value != string.Empty)
            {
                kb.Content = Content_Value.Trim();
            }
            if (KeyWord_Value != string.Empty)
            {
                kb.KeyWord = KeyWord_Value.Trim();
            }
            Session["its_KnowledgeBaseEntity"] = kb;
            BindDataList();
            TabOptionWebControls1.SelectIndex = 0;
        }
    }
}
